package tests;

import static org.junit.Assert.*;


import java.sql.Timestamp;
import java.util.Date;

import model.Email;
import model.EmailBuilder;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
 * This class tests the EmailBuilder class
 * 
 * @author buthainahaldosary
 * @since May 2013
 *
 */

public class TestEmailBuilder {
	
	 EmailBuilder emBuilder,result,emb;
	 Email em;
	 Date date;
	 Timestamp currentTime;
	 
	 /**
		 * This method is called before every test case.
		 */
	@Before
	public void setUp()
	{
		emBuilder=new EmailBuilder();
		date= new Date();
		currentTime=(new Timestamp(date.getTime()));
	}
	
	/**
	 * This method is called after every test case.
	 */
	@After
	public void tearDown()
	{
		emBuilder=null;
		result=null;
		System.gc();
		
		
	}
	
	/**
	 * This test case tests the withTo method.
	 */
	@Test
	public void testWithTo() {
		result=emBuilder.withTo("You@gmail.com");
		assertEquals("You@gmail.com",result.getTo());
	}

	/**
	 * This test case tests the withFrom method.
	 */
	@Test
	public void testWithFrom() {
		result=emBuilder.withFrom("Me@gmail.com");
		assertEquals("Me@gmail.com",result.getFrom());
	}

	/**
	 * This test case tests the withSubject method.
	 */
	@Test
	public void testWithSubject() {
		result=emBuilder.withSubject("Hello!");
		assertEquals("Hello!",result.getSubject());
	}

	/**
	 * This test case tests the withBody method.
	 */
	@Test
	public void testWithBody() {
		result=emBuilder.withBody("Just dropping by to say hello!");
		assertEquals("Just dropping by to say hello!",result.getBody());
	}

	/**
	 * This test case tests the withRead method.
	 */
	@Test
	public void testWithRead() {
		result=emBuilder.withRead(false);
		assertEquals(false,result.isRead());
	}

	/**
	 * This test case tests the withTimestamp method.
	 */
	@Test
	public void testWithTimestamp() {
		
		result=emBuilder.withTimestamp(currentTime);
		assertEquals(currentTime,result.getTimestamp());
	}

	/**
	 * This test case tests the withFolderId method.
	 */
	@Test
	public void testWithFolderId() {
		result=emBuilder.withFolderId(1);
		assertEquals(1,result.getFolderId());
	}

	/**
	 * This test case tests the Build method.
	 */
	@Test
	public void testBuild() {
		emb=new EmailBuilder();
		 em=emb.withTo("Sara@gmail.com").withFrom("Buthainah.aldosary@gmail.com").withSubject("Hello").withBody("Just dropping by to say hello")
				 .withRead(false).withTimestamp(currentTime).withFolderId(1).build();
		 assertEquals("Sara@gmail.com",em.getTo());
		 assertEquals("Buthainah.aldosary@gmail.com",em.getFrom());
		 assertEquals("Hello",em.getSubject());
		 assertEquals("Just dropping by to say hello",em.getBody());
		 assertEquals(false,em.isRead());
		 assertEquals(currentTime,em.getTimestamp());
		 assertEquals(1,em.getFolderId());
	}

}
